package com.recyclebanner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;
import java.util.Map;

/**
 * 无限循环适配器
 * Created by cys on 2015/11/4.
 */
public class RecycleBannerAdapter extends InfinitePagerAdapter {
    private List list;
    private InitRecycleViewpager.BannerItemResponse itemClickPostion;
    private int resId = 0;

    public void setItemClickPostion(InitRecycleViewpager.BannerItemResponse itemClickPostion) {
        this.itemClickPostion = itemClickPostion;
    }

    private Context context;

    public RecycleBannerAdapter(int resId, List list, Context context) {
        this.list = list;
        this.context = context;
        this.resId = resId;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(resId, null);
            holder = new ViewHolder();
            holder.convertView = convertView;
            convertView.setTag(holder);
        }

        if (itemClickPostion != null)
            itemClickPostion.responseData(holder.convertView , position);

        return convertView;
    }

    class ViewHolder {
        View convertView;
    }
}
